home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-16 | 4.4 KB | 169 lines | [TEXT/CWIE] |
- // ===========================================================================
- // CProbDialog.cp ©1995-97 Timo Eloranta All rights reserved.
- // ===========================================================================
-
- #include "CProbDialog.h"
- #include "GraphGA_PaneIDs.h"
-
- #include <PP_Messages.h>
-
- #include <LCaption.h>
- #include <LGAPushButton.h>
-
- #include "CAGASlider.h"
-
- // ---------------------------------------------------------------------------
- // • CProbDialog
- //
- // Called by: URegistrar::CreateObject
- // ---------------------------------------------------------------------------
-
- CProbDialog::CProbDialog( LStream *inStream )
- : LGADialogBox( inStream )
- {
- }
-
- // ---------------------------------------------------------------------------
- // • InitDialog
- //
- // Called by: CGraphGAApp::ObeyCommand
- // ---------------------------------------------------------------------------
-
- void
- CProbDialog::InitDialog()
- {
- mCrossCapt = (LCaption*) this -> FindPaneByID( capt_Crossover );
- mMutaCapt = (LCaption*) this -> FindPaneByID( capt_Mutation );
-
- mFactoryButton = (LGAPushButton*) this -> FindPaneByID( but_FactorySettings);
-
- mCrossSlider = (CAGASlider *) this -> FindPaneByID( slid_CrossSlider);
- mMutaSlider = (CAGASlider *) this -> FindPaneByID( slid_MutaSlider);
-
- if ( mFactoryButton)
- mFactoryButton -> AddListener( this );
-
- if ( mCrossSlider )
- mCrossSlider -> AddListener( this );
-
- if ( mMutaSlider )
- mMutaSlider -> AddListener( this );
- }
-
- // ---------------------------------------------------------------------------
- // • SetValues
- //
- // Called by: CGraphGAApp::ObeyCommand
- // ---------------------------------------------------------------------------
-
- void
- CProbDialog::SetValues( Int32 inCrossValue, Int32 inMutaValue )
- {
- if ( mCrossCapt )
- mCrossCapt -> SetValue( inCrossValue );
- if ( mCrossSlider )
- mCrossSlider -> SetValue( inCrossValue );
-
- if ( mMutaCapt )
- mMutaCapt -> SetValue( inMutaValue );
- if ( mMutaSlider )
- mMutaSlider -> SetValue( inMutaValue );
- }
-
- // ---------------------------------------------------------------------------
- // • GetValues
- //
- // Called by: CGraphGAApp::SetProbsFromDialog
- // CProbDialog::AdjustFactoryButton
- // ---------------------------------------------------------------------------
-
- void
- CProbDialog::GetValues( Int32 &outCrossValue, Int32 &outMutaValue )
- {
- if ( mCrossCapt )
- outCrossValue = mCrossCapt -> GetValue();
- if ( mMutaCapt )
- outMutaValue = mMutaCapt -> GetValue();
- }
-
- // ---------------------------------------------------------------------------
- // • ListenToMessage
- //
- // Called by: LBroadcaster::BroadcastMessage
- // ---------------------------------------------------------------------------
-
- void
- CProbDialog::ListenToMessage(
- MessageT inMessage,
- void *ioParam )
- {
- switch ( inMessage ) {
-
- case msg_CrossSlider:
- if ( mCrossCapt ) {
- mCrossCapt -> SetValue( *(Int32 *) ioParam );
- mCrossCapt -> Draw(nil);
- AdjustFactoryButton();
- }
- break;
-
- case msg_MutaSlider:
- if ( mMutaCapt ) {
- mMutaCapt -> SetValue( *(Int32 *) ioParam );
- mMutaCapt -> Draw(nil);
- AdjustFactoryButton();
- }
- break;
-
- case msg_FactorySettings:
- SetValues( DEFAULT_CROSSOVER_PROB, DEFAULT_MUTATION_PROB );
- break;
-
- default:
- LGADialogBox::ListenToMessage( inMessage, ioParam );
- break;
- }
- }
-
- // ---------------------------------------------------------------------------
- // • AdjustFactoryButton (PRIVATE)
- //
- // Called by: CProbDialog::ListenToMessage
- // ---------------------------------------------------------------------------
-
- void
- CProbDialog::AdjustFactoryButton( )
- {
- Int32 theCrossValue, theMutaValue;
-
- GetValues( theCrossValue, theMutaValue );
-
- if ( theCrossValue == DEFAULT_CROSSOVER_PROB &&
- theMutaValue == DEFAULT_MUTATION_PROB )
- mFactoryButton -> Disable();
- else
- if ( ! mFactoryButton -> IsEnabled() )
- mFactoryButton -> Enable();
- }
-
- // ---------------------------------------------------------------------------
- // • FindCommandStatus
- //
- // Called by: LCommander::ProcessCommandStatus
- // ---------------------------------------------------------------------------
- // Disable all menu items except for the one which opens the About box.
-
- void
- CProbDialog::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean& /* outUsesMark */,
- Char16& /* outMark */,
- Str255 /* outName */)
- {
- outEnabled = false;
- if (inCommand == cmd_About) {
- outEnabled = true;
- }
- }
-